#放数据库有关的文件
from unittest import result

import pymysql
#定义和数据库的连接
conn = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    passwd='123456',
    db='assistant',
    charset='utf8',
    cursorclass=pymysql.cursors.DictCursor
)
#根据用户名查询用户是否存在的函数
def query_user_no_exits(username):
    sql = 'select * from sys_user where username = %s'
    cur = conn.cursor()
    cur.execute(sql, [username])
    result = cur.fetchone()
    if result is None:
        return False
    else:
        return True

def query_login_no_exits(username):
    sql = 'select * from sys_user where username = %s'
    cur = conn.cursor()
    cur.execute(sql, [username])
    result = cur.fetchone()
    if result is None:
        return True
    else:
        return False

def query_password_exits(username):
    sql = 'select password from sys_user where username = %s'
    cur = conn.cursor()
    cur.execute(sql, [username])
    result = cur.fetchone()
    return result


#根据用户名和密码添加数据的函数
def add_user(username, password):
    sql = 'insert into sys_user (username, password) values (%s, %s)'
    cur = conn.cursor()
    cur.execute(sql, [username, password])
    conn.commit()